import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n  = scan.nextInt() ;
        int bV = scan.nextInt() ;
        int[] v = new int[n + 1] ;
        int[] s = new int[n + 1] ;
        for (int i = 1 ; i <= n ; i ++) {
            v[i] = scan.nextInt() ;
            s[i] = scan.nextInt() ;
        }
        int[] dp = new int[bV + 1] ;
        for (int i = 1 ; i <= n ; i ++) {
            for (int j = 1 ; j <= bV ; j ++) {
                if (j >= v[i]) {
                    dp[j] = Math.max(dp[j], dp[j - v[i]] + s[i]);
                }
            }
        }
        System.out.println(dp[bV]);

        dp = new int[bV + 1] ;
        for(int i=1 ; i<= bV ; i ++) dp[i] = -1 ;
        for (int i = 1 ; i <= n ; i ++) {
            for (int j = 1 ; j <= bV ; j ++) {
                if (j >= v[i] && dp[j-v[i]] != -1) {
                    dp[j] = Math.max(dp[j], dp[j - v[i]] + s[i]);
                }
            }
        }
        System.out.println(dp[bV]>0?dp[bV]:0);



    }
}